home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: lut.ac.uk!elrs1
- From: R.Sheikhan@lut.ac.uk (R.Sheikhan)
- Subject: problem with types
- Originator: elrs1@hpc.lut.ac.uk
- Sender: usenet@lut.ac.uk (Usenet-News)
- Message-ID: <Do5Mu9.6nv@lut.ac.uk>
- Date: Tue, 12 Mar 1996 12:32:33 GMT
- X-Nntp-Posting-Host: hpc.lut.ac.uk
- Reply-To: R.Sheikhan@lut.ac.uk (R.Sheikhan)
- Organization: Loughborough University, UK.
-
- Hi;
- When I use int to declare my variable type my programme works fine, but
- when I use long it doesn't work. Every thing looks ok but I just can't
- figure out why. I would appreciate any help.
-
- Many thanks
- Rez
-
- ----------MY Programme----------------------------------------------------
-
-
- #include <stdio.h>
-
- long x, y;
-
- main()
- {
- long Numbers[100];
- int i = -1;
-
- do
- {
- i++;
- printf("Enter number: ");
- scanf("%ld", &Numbers[i]);
- }
- while ((i<100) && (Numbers[i] != 0));
-
- getchar();
-
- printf(" LCM is %ld\n", LCM_Array(Numbers));
- print_Array(Numbers);
- getchar();
- }
-
- LCM_Array(Array)
- long *Array;
- {
- long loop_counter;
- long sofar;
-
- loop_counter = 0;
- sofar = 1;
-
- while (Array[loop_counter] != 0)
- {
- printf("sofar= %ld, loop_counter = %ld\n", sofar, loop_counter);
- sofar = lcm(sofar, Array[loop_counter]);
- loop_counter ++;
- }
- return sofar;
- }
-
-
- gcd(long a,long b)
- {
- long c;
-
- while ( b != 0)
- {
- printf(" a= %ld, b= %ld\n", a,b);
- c = a % b;
- /* printf("a= %ld, b= %ld, c= %ld \n", a, b, c); */
- a = b;
- b = c;
- }
- return a;
- }
-
- lcm(long x,long y)
- {
- return (x*y)/gcd(x,y);
- }
-
- print_Array( Numbers)
- long *Numbers;
- {
- int i;
- for (i=0; i<3; i++)
- {
- printf(" The Array is : %ld\n", Numbers[i]);
- }
- }
-
-
-
-